package com.xiaoyun.advice;

import com.xiaoyun.vo.ErrorInfo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ErrorInfo<String> errHandler(HttpServletRequest request, Exception ex) {
        ErrorInfo<String> info = new ErrorInfo<>();
        info.setCode(ErrorInfo.ERROR);
        info.setMessage(ex.getMessage());
        info.setDate("Do Not Have Return Date");
        info.setUrl(request.getRequestURL().toString());
        return info;
    }

}
